package phone.qyg.com.qyg.adapter;

import android.content.Context;

import com.app.adapter.recycler.MultiItemTypeAdapter;
import com.app.adapter.recycler.base.ItemViewDelegate;
import com.app.adapter.recycler.base.ViewHolder;
import com.app.utils.OptionImageUtils;

import java.util.List;

import phone.qyg.com.qyg.R;
import phone.qyg.com.qyg.model.Activity;
import phone.qyg.com.qyg.model.Content;
import phone.qyg.com.qyg.model.Course;
import phone.qyg.com.qyg.model.Venues;

/**
 * 作者：lblbh on 2017/11/28 17:06
 * 邮箱：lanbuhan@163.com
 * 功能：全部适配器
 */
public class AllAdapter extends MultiItemTypeAdapter<Object> {

    public AllAdapter(Context context, List<Object> datas) {
        super(context, datas);
        addItemViewDelegate(new VenuesAdapter());
        addItemViewDelegate(new ContentAdapter());
        addItemViewDelegate(new CourseAdapter());
        addItemViewDelegate(new ActAdapter());
    }

    public class ActAdapter implements ItemViewDelegate<Object> {

        @Override
        public int getItemViewLayoutId() {
            return R.layout.home_item_act;
        }

        @Override
        public boolean isForViewType(Object item, int position) {
            return (item instanceof Activity);
        }

        @Override
        public void convert(ViewHolder holder, Object model, int position) {
            //活动
            Activity act = (Activity) model;
            holder.setText(R.id.item_title, act.title);
            holder.setText(R.id.item_address, act.startTime);
            holder.setText(R.id.item_map, act.address);
            holder.setText(R.id.item_state, String.valueOf(act.statusName));
            holder.setTextColor(R.id.item_state, act.color);
            holder.setImage(R.id.item_img,act.fixImgUrl, OptionImageUtils.getRectRatioAct());
        }
    }


    public class CourseAdapter implements ItemViewDelegate<Object> {

        @Override
        public int getItemViewLayoutId() {
            return R.layout.home_item_course;
        }

        @Override
        public boolean isForViewType(Object item, int position) {
            return (item instanceof Course);
        }

        @Override
        public void convert(ViewHolder holder, Object model, int position) {
            //课程
            Course course = (Course) model;
            holder.setText(R.id.item_title, course.title);
            holder.setText(R.id.item_address, course.startTime);
            holder.setText(R.id.item_number, String.valueOf(course.regCount));
            holder.setImage(R.id.item_img,course.fixImgUrl, OptionImageUtils.getRectRatio43());
        }
    }

    public class ContentAdapter implements ItemViewDelegate<Object> {

        @Override
        public int getItemViewLayoutId() {
            return R.layout.home_item_content;
        }

        @Override
        public boolean isForViewType(Object item, int position) {
            return (item instanceof Content);
        }

        @Override
        public void convert(ViewHolder holder, Object model, int position) {
            //新闻
            Content content = (Content) model;
            holder.setText(R.id.item_title, content.title);
        }
    }

    public class VenuesAdapter implements ItemViewDelegate<Object> {

        @Override
        public int getItemViewLayoutId() {
            return R.layout.home_item_venues;
        }

        @Override
        public boolean isForViewType(Object item, int position) {
            return (item instanceof Venues);
        }

        @Override
        public void convert(ViewHolder holder, Object model, int position) {
            //场馆
            Venues venue = (Venues) model;
            holder.setText(R.id.item_title, venue.title);
            holder.setImage(R.id.item_img,venue.fixImgUrl, OptionImageUtils.getRectRatio43());
        }
    }
}
